package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1763 {
    public long startExecuteTime = System.currentTimeMillis();


    /*
     * @param 此题目参考了别人代码
     * 不是因为复杂，而是因为经典
     * 未来需要再次复习此道题目
     * @return:
     */
    class Solution {
        public String longestNiceSubstring(String s) {
            int len = s.length();
            int index = 0, Maxlen = 0;
            for (int i = 0; i < len; i++) {
                int ch1 = 0;// 记录小写
                int ch2 = 0;// 记录大写
                for (int j = i; j < len; j++) {
                    char c = s.charAt(j);
                    //小写
                    if (Character.isLowerCase(c))
                        // 或运算， 当前后两个不一样的时候 ch1会变 如果一样的话 ch1就不会变
                        ch1 |= (1 << (c - 'a'));
                        // 大写
                    else
                        ch2 |= (1 << (c - 'A'));
                    if (ch1 == ch2 && j - i + 1 > Maxlen) {
                        index = i;
                        Maxlen = j - i + 1;
                    }
                }
            }
            //返回最终结果
            return s.substring(index, index + Maxlen);
        }
    }


    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC1763 an = new LC1763();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
